scide: refactoring - move ReferencesDialog to lookup_dialog.xpp files
[supercollider.git] / examples / CocoaBridge / SCNSObject control actions.scd
blob46d01eb165c7d8d50a46a653ba71a923634be19b
2 // blackrain
3 // NSButton
4 w = SCNSObject("NSWindow", "initWithContentRect:styleMask:backing:defer:", [ Rect(100,600,500,200), 10, 2, 1]);
6 w.invoke("makeKeyAndOrderFront:", [nil], true);
7 w.invoke("setTitle:", [ "Hello, World!" ], true);
10 b = SCNSObject("NSButton", "initWithFrame:", [ Rect(10,10,75,22) ]);
11 b.invoke("setBezelStyle:", [10], true);
13 v = w.invoke("contentView");
14 v.invoke("addSubview:", [ b ], true);
17 w.setDelegate;
19         // - (void)buttonAction:(id)sender;
20         w.nsDelegate.addMethod("buttonAction:", "v", "@", { arg method, args;
21                 var btn = args.at(0).asNSReturn; // args.at(0) is the button
22                 
23                 btn.invoke("state").postln;
24                 
25         });
28 b.invoke("setTarget:", [ w.nsDelegate ], false);
29 b.invoke("setAction:", [ "buttonAction:" ], false); // SEL are recognized now
33 w.release;
35 SCNSObject.dumpPool;
37 SCNSObject.freePool;
39 // NSSlider
40 w = SCNSObject("NSWindow", "initWithContentRect:styleMask:backing:defer:", [ Rect(100,650,500,40), 10, 2, 1]);
42 w.invoke("makeKeyAndOrderFront:", [nil], true);
43 w.invoke("setTitle:", [ "Hello, World!" ], true);
46 l = SCNSObject("NSSlider", "initWithFrame:", [ Rect(10,10,480,22) ]);
48 v = w.invoke("contentView");
49 v.invoke("addSubview:", [ l ], true);
52 w.setDelegate;
54         w.nsDelegate.addMethod("sliderAction:", "v", "@", { arg method, args;
55                 var slider = args.at(0).asNSReturn;
56                 
57                 slider.invoke("doubleValue").postln;
58                 
59         });
62 l.invoke("setTarget:", [ w.nsDelegate ], false);
63 l.invoke("setAction:", [ "sliderAction:" ], false);
67 SCNSObject.dumpPool;
69 SCNSObject.freePool;